Skip to main content

nullif

nullif

Description

Syntax:

nullif(expr1, expr2)

If the two parameters are equal, the function will return null. Otherwise, it will return the value of the first parameter. This function has the same effect as case when:

CASE
WHEN expr1 = expr2 THEN NULL
ELSE expr1
END

Example

mysql> select nullif(1,1);
+--------------+
| nullif(1, 1) |
+--------------+
| NULL |
+--------------+

mysql> select nullif(1,0);
+--------------+
| nullif(1, 0) |
+--------------+
| 1 |
+--------------+

Keywords

NULLIF